<%@ page import="java.util.ArrayList" %>
<%@ page import="com.model.Question" %>
<%@ page import="com.model.Option" %>
<%@ page import="com.model.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    if (session.getAttribute("loginUser") == null) {
        response.sendRedirect("login.jsp");
    } else {
%>
<jsp:useBean id="loginUser" type="com.model.User" scope="session"/>

<html>
<head>
    <title>考试页面</title>
</head>
<body>
<p>你好,
    <jsp:getProperty name="loginUser" property="username"/>
    <br>
    你上次的考试分数为:
    <jsp:getProperty name="loginUser" property="score"/>
    分</p>
<hr>
<form method="post" action="score.do">
    <ol>
        <%
                ArrayList<Question> questions = (ArrayList<Question>) session.getAttribute("questions");
                for (Question question : questions) {
                    int type = question.getType();
                    out.println("<li>" + question.getContext());
                    if (type == 1) {
                        for (Option option : question.getOptions()) {
                            out.println(
                                    "<input type=\"radio\" name=\"" + question.getqId() + "\" value=\"" + option.getoId()
                                            + "\">" + option.getContext());
                        }
                    }
                    if (type == 2) {
                        for (Option option : question.getOptions()) {
                            out.println(
                                    "<input type=\"checkbox\" name=\"" + question.getqId() + "\" value=\"" + option.getoId()
                                            + "\">" + option.getContext());
                        }
                    }
                    if (type == 3) {
                        out.println("<input type=\"text\" name=\"" + question.getqId() + "\">");
                    }
                    out.println("</li>");
                }
            }
        %>
    </ol>
    <input type="submit" name="submit" value="提交">
    <input type="reset" name="reset" value="重置">
</form>
<hr>
<p><a href="menu.jsp">返回菜单</a></p>
</body>
</html>
